
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 02/14/2011 16:39:30
-- Generated from EDMX file: C:\vowei\src\vowei.modelfist.data\Models\VoweiModel.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [Vowei.Data.VoweiContext];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_MilestoneMilestone]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[MilestoneSet] DROP CONSTRAINT [FK_MilestoneMilestone];
GO
IF OBJECT_ID(N'[dbo].[FK_CommentComment_Comment]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[CommentComment] DROP CONSTRAINT [FK_CommentComment_Comment];
GO
IF OBJECT_ID(N'[dbo].[FK_CommentComment_Comment1]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[CommentComment] DROP CONSTRAINT [FK_CommentComment_Comment1];
GO
IF OBJECT_ID(N'[dbo].[FK_MilestoneComment_Milestone]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[MilestoneComment] DROP CONSTRAINT [FK_MilestoneComment_Milestone];
GO
IF OBJECT_ID(N'[dbo].[FK_MilestoneComment_Comments]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[MilestoneComment] DROP CONSTRAINT [FK_MilestoneComment_Comments];
GO
IF OBJECT_ID(N'[dbo].[FK_TicketComment_Ticket]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[TicketComment] DROP CONSTRAINT [FK_TicketComment_Ticket];
GO
IF OBJECT_ID(N'[dbo].[FK_TicketComment_Comments]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[TicketComment] DROP CONSTRAINT [FK_TicketComment_Comments];
GO
IF OBJECT_ID(N'[dbo].[FK_RiskTicket_Risk]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[RiskTicket] DROP CONSTRAINT [FK_RiskTicket_Risk];
GO
IF OBJECT_ID(N'[dbo].[FK_RiskTicket_RelatedTickets]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[RiskTicket] DROP CONSTRAINT [FK_RiskTicket_RelatedTickets];
GO
IF OBJECT_ID(N'[dbo].[FK_ProjectRisk_Project]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ProjectRisk] DROP CONSTRAINT [FK_ProjectRisk_Project];
GO
IF OBJECT_ID(N'[dbo].[FK_ProjectRisk_Risk]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ProjectRisk] DROP CONSTRAINT [FK_ProjectRisk_Risk];
GO
IF OBJECT_ID(N'[dbo].[FK_RiskMitigationPlans_Risk]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[RiskMitigationPlans] DROP CONSTRAINT [FK_RiskMitigationPlans_Risk];
GO
IF OBJECT_ID(N'[dbo].[FK_RiskMitigationPlans_MitigationPlan]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[RiskMitigationPlans] DROP CONSTRAINT [FK_RiskMitigationPlans_MitigationPlan];
GO
IF OBJECT_ID(N'[dbo].[FK_RiskContingencyPlan_Risk]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[RiskContingencyPlan] DROP CONSTRAINT [FK_RiskContingencyPlan_Risk];
GO
IF OBJECT_ID(N'[dbo].[FK_RiskContingencyPlan_ContingencyPlan]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[RiskContingencyPlan] DROP CONSTRAINT [FK_RiskContingencyPlan_ContingencyPlan];
GO
IF OBJECT_ID(N'[dbo].[FK_RequirementTicket_Requirement]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[RequirementTicket] DROP CONSTRAINT [FK_RequirementTicket_Requirement];
GO
IF OBJECT_ID(N'[dbo].[FK_RequirementTicket_Ticket]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[RequirementTicket] DROP CONSTRAINT [FK_RequirementTicket_Ticket];
GO
IF OBJECT_ID(N'[dbo].[FK_PermissionSetPermission_PermissionSet]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PermissionSetPermission] DROP CONSTRAINT [FK_PermissionSetPermission_PermissionSet];
GO
IF OBJECT_ID(N'[dbo].[FK_PermissionSetPermission_Permission]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PermissionSetPermission] DROP CONSTRAINT [FK_PermissionSetPermission_Permission];
GO
IF OBJECT_ID(N'[dbo].[FK_AcePermission_Ace]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[AcePermission] DROP CONSTRAINT [FK_AcePermission_Ace];
GO
IF OBJECT_ID(N'[dbo].[FK_AcePermission_Permission]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[AcePermission] DROP CONSTRAINT [FK_AcePermission_Permission];
GO
IF OBJECT_ID(N'[dbo].[FK_EmployeeEmployee]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[EmployeeSet] DROP CONSTRAINT [FK_EmployeeEmployee];
GO
IF OBJECT_ID(N'[dbo].[FK_EmployeeEmployee1]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[EmployeeSet] DROP CONSTRAINT [FK_EmployeeEmployee1];
GO
IF OBJECT_ID(N'[dbo].[FK_AssignmentProject]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[AssignmentSet] DROP CONSTRAINT [FK_AssignmentProject];
GO
IF OBJECT_ID(N'[dbo].[FK_EmployeeAssignment]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[AssignmentSet] DROP CONSTRAINT [FK_EmployeeAssignment];
GO
IF OBJECT_ID(N'[dbo].[FK_RequirementMilestone]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[TicketSet_Requirement] DROP CONSTRAINT [FK_RequirementMilestone];
GO
IF OBJECT_ID(N'[dbo].[FK_ChangeSetProject]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ChangeSetSet] DROP CONSTRAINT [FK_ChangeSetProject];
GO
IF OBJECT_ID(N'[dbo].[FK_Task_inherits_Ticket]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[TicketSet_Task] DROP CONSTRAINT [FK_Task_inherits_Ticket];
GO
IF OBJECT_ID(N'[dbo].[FK_Risk_inherits_Task]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[TicketSet_Risk] DROP CONSTRAINT [FK_Risk_inherits_Task];
GO
IF OBJECT_ID(N'[dbo].[FK_Project_inherits_Milestone]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[MilestoneSet_Project] DROP CONSTRAINT [FK_Project_inherits_Milestone];
GO
IF OBJECT_ID(N'[dbo].[FK_Requirement_inherits_Ticket]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[TicketSet_Requirement] DROP CONSTRAINT [FK_Requirement_inherits_Ticket];
GO
IF OBJECT_ID(N'[dbo].[FK_PermissionSet_inherits_Permission]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PermissionSet_PermissionSet] DROP CONSTRAINT [FK_PermissionSet_inherits_Permission];
GO
IF OBJECT_ID(N'[dbo].[FK_Bug_inherits_Ticket]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[TicketSet_Bug] DROP CONSTRAINT [FK_Bug_inherits_Ticket];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[MilestoneSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[MilestoneSet];
GO
IF OBJECT_ID(N'[dbo].[CommentSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[CommentSet];
GO
IF OBJECT_ID(N'[dbo].[TicketSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TicketSet];
GO
IF OBJECT_ID(N'[dbo].[PermissionSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[PermissionSet];
GO
IF OBJECT_ID(N'[dbo].[AceSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[AceSet];
GO
IF OBJECT_ID(N'[dbo].[EmployeeSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[EmployeeSet];
GO
IF OBJECT_ID(N'[dbo].[AssignmentSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[AssignmentSet];
GO
IF OBJECT_ID(N'[dbo].[ChangeSetSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ChangeSetSet];
GO
IF OBJECT_ID(N'[dbo].[TicketSet_Task]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TicketSet_Task];
GO
IF OBJECT_ID(N'[dbo].[TicketSet_Risk]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TicketSet_Risk];
GO
IF OBJECT_ID(N'[dbo].[MilestoneSet_Project]', 'U') IS NOT NULL
    DROP TABLE [dbo].[MilestoneSet_Project];
GO
IF OBJECT_ID(N'[dbo].[TicketSet_Requirement]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TicketSet_Requirement];
GO
IF OBJECT_ID(N'[dbo].[PermissionSet_PermissionSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[PermissionSet_PermissionSet];
GO
IF OBJECT_ID(N'[dbo].[TicketSet_Bug]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TicketSet_Bug];
GO
IF OBJECT_ID(N'[dbo].[CommentComment]', 'U') IS NOT NULL
    DROP TABLE [dbo].[CommentComment];
GO
IF OBJECT_ID(N'[dbo].[MilestoneComment]', 'U') IS NOT NULL
    DROP TABLE [dbo].[MilestoneComment];
GO
IF OBJECT_ID(N'[dbo].[TicketComment]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TicketComment];
GO
IF OBJECT_ID(N'[dbo].[RiskTicket]', 'U') IS NOT NULL
    DROP TABLE [dbo].[RiskTicket];
GO
IF OBJECT_ID(N'[dbo].[ProjectRisk]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ProjectRisk];
GO
IF OBJECT_ID(N'[dbo].[RiskMitigationPlans]', 'U') IS NOT NULL
    DROP TABLE [dbo].[RiskMitigationPlans];
GO
IF OBJECT_ID(N'[dbo].[RiskContingencyPlan]', 'U') IS NOT NULL
    DROP TABLE [dbo].[RiskContingencyPlan];
GO
IF OBJECT_ID(N'[dbo].[RequirementTicket]', 'U') IS NOT NULL
    DROP TABLE [dbo].[RequirementTicket];
GO
IF OBJECT_ID(N'[dbo].[PermissionSetPermission]', 'U') IS NOT NULL
    DROP TABLE [dbo].[PermissionSetPermission];
GO
IF OBJECT_ID(N'[dbo].[AcePermission]', 'U') IS NOT NULL
    DROP TABLE [dbo].[AcePermission];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'MilestoneSet'
CREATE TABLE [dbo].[MilestoneSet] (
    [ID] uniqueidentifier  NOT NULL,
    [Title] nvarchar(max)  NOT NULL,
    [Status] nvarchar(max)  NOT NULL,
    [Progress] real  NOT NULL,
    [Reporter] nvarchar(max)  NOT NULL,
    [OpenDate] datetime  NOT NULL,
    [LastModifiedBy] nvarchar(max)  NOT NULL,
    [LastModified] datetime  NOT NULL,
    [ClosedDate] datetime  NULL,
    [DueDate] datetime  NULL,
    [StartDate] datetime  NULL,
    [Parent_ID] uniqueidentifier  NULL
);
GO

-- Creating table 'CommentSet'
CREATE TABLE [dbo].[CommentSet] (
    [ID] uniqueidentifier  NOT NULL,
    [PostType] nvarchar(max)  NULL,
    [PostId] uniqueidentifier  NOT NULL,
    [Text] nvarchar(max)  NOT NULL,
    [User] nvarchar(max)  NOT NULL,
    [CommentDate] datetime  NOT NULL
);
GO

-- Creating table 'TicketSet'
CREATE TABLE [dbo].[TicketSet] (
    [ID] uniqueidentifier  NOT NULL,
    [Description] nvarchar(max)  NOT NULL,
    [OpenDate] datetime  NOT NULL,
    [ClosedDate] datetime  NULL,
    [Reporter] nvarchar(max)  NOT NULL,
    [AssignedTo] nvarchar(max)  NOT NULL,
    [LastModified] datetime  NOT NULL,
    [TagText] nvarchar(max)  NULL,
    [Title] nvarchar(max)  NOT NULL,
    [LastModifiedBy] nvarchar(max)  NOT NULL,
    [Progress] real  NOT NULL,
    [Priority] nvarchar(max)  NULL,
    [Status] nvarchar(max)  NULL
);
GO

-- Creating table 'PermissionSet'
CREATE TABLE [dbo].[PermissionSet] (
    [ID] uniqueidentifier  NOT NULL,
    [Title] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'AceSet'
CREATE TABLE [dbo].[AceSet] (
    [ID] uniqueidentifier  NOT NULL,
    [RoleName] nvarchar(max)  NOT NULL,
    [UserName] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'EmployeeSet'
CREATE TABLE [dbo].[EmployeeSet] (
    [Title] nvarchar(max)  NULL,
    [Department] nvarchar(max)  NULL,
    [Level] nvarchar(max)  NULL,
    [Telephone] nvarchar(max)  NULL,
    [OnboardDate] datetime  NOT NULL,
    [PotentialQuitDate] datetime  NULL,
    [IsConfirmed] bit  NOT NULL,
    [Email] nvarchar(max)  NOT NULL,
    [DisplayName] nvarchar(max)  NULL,
    [Company] nvarchar(max)  NULL,
    [ID] smallint  NOT NULL,
    [ReportTo_ID] smallint  NOT NULL,
    [Replacement_ID] smallint  NOT NULL
);
GO

-- Creating table 'AssignmentSet'
CREATE TABLE [dbo].[AssignmentSet] (
    [ID] uniqueidentifier  NOT NULL,
    [AvailableHours] real  NOT NULL,
    [Project_ID] uniqueidentifier  NOT NULL,
    [User_ID] smallint  NOT NULL
);
GO

-- Creating table 'ChangeSetSet'
CREATE TABLE [dbo].[ChangeSetSet] (
    [ID] uniqueidentifier  NOT NULL,
    [Title] nvarchar(max)  NOT NULL,
    [ChangedFileList] nvarchar(max)  NOT NULL,
    [TicketId] uniqueidentifier  NOT NULL,
    [Project_ID] uniqueidentifier  NOT NULL
);
GO

-- Creating table 'TicketSet_Task'
CREATE TABLE [dbo].[TicketSet_Task] (
    [IsRecursive] bit  NOT NULL,
    [RecursiveEndDate] datetime  NULL,
    [StartDate] datetime  NULL,
    [DueDate] datetime  NULL,
    [ID] uniqueidentifier  NOT NULL
);
GO

-- Creating table 'TicketSet_Risk'
CREATE TABLE [dbo].[TicketSet_Risk] (
    [Possibility] float  NOT NULL,
    [Impact] float  NOT NULL,
    [RootCause] nvarchar(max)  NOT NULL,
    [ID] uniqueidentifier  NOT NULL
);
GO

-- Creating table 'MilestoneSet_Project'
CREATE TABLE [dbo].[MilestoneSet_Project] (
    [Owner] nvarchar(max)  NOT NULL,
    [ScmUrl] nvarchar(max)  NOT NULL,
    [ScmType] nvarchar(max)  NOT NULL,
    [ID] uniqueidentifier  NOT NULL
);
GO

-- Creating table 'TicketSet_Requirement'
CREATE TABLE [dbo].[TicketSet_Requirement] (
    [BusinessValue] real  NOT NULL,
    [ID] uniqueidentifier  NOT NULL,
    [Milestone_ID] uniqueidentifier  NOT NULL
);
GO

-- Creating table 'PermissionSet_PermissionSet'
CREATE TABLE [dbo].[PermissionSet_PermissionSet] (
    [ID] uniqueidentifier  NOT NULL
);
GO

-- Creating table 'TicketSet_Bug'
CREATE TABLE [dbo].[TicketSet_Bug] (
    [ReproStep] nvarchar(max)  NOT NULL,
    [ID] uniqueidentifier  NOT NULL
);
GO

-- Creating table 'CommentComment'
CREATE TABLE [dbo].[CommentComment] (
    [Comments_ID] uniqueidentifier  NOT NULL,
    [CommentComment_Comment_ID] uniqueidentifier  NOT NULL
);
GO

-- Creating table 'MilestoneComment'
CREATE TABLE [dbo].[MilestoneComment] (
    [MilestoneComment_Comments_ID] uniqueidentifier  NOT NULL,
    [Comments_ID] uniqueidentifier  NOT NULL
);
GO

-- Creating table 'TicketComment'
CREATE TABLE [dbo].[TicketComment] (
    [TicketComment_Comments_ID] uniqueidentifier  NOT NULL,
    [Comments_ID] uniqueidentifier  NOT NULL
);
GO

-- Creating table 'RiskTicket'
CREATE TABLE [dbo].[RiskTicket] (
    [RiskTicket_RelatedTickets_ID] uniqueidentifier  NOT NULL,
    [RelatedTickets_ID] uniqueidentifier  NOT NULL
);
GO

-- Creating table 'ProjectRisk'
CREATE TABLE [dbo].[ProjectRisk] (
    [AffectedProjects_ID] uniqueidentifier  NOT NULL,
    [Risks_ID] uniqueidentifier  NOT NULL
);
GO

-- Creating table 'RiskMitigationPlans'
CREATE TABLE [dbo].[RiskMitigationPlans] (
    [RiskMitigationPlans_MitigationPlan_ID] uniqueidentifier  NOT NULL,
    [MitigationPlans_ID] uniqueidentifier  NOT NULL
);
GO

-- Creating table 'RiskContingencyPlan'
CREATE TABLE [dbo].[RiskContingencyPlan] (
    [RiskContingencyPlan_ContingencyPlan_ID] uniqueidentifier  NOT NULL,
    [ContingencyPlans_ID] uniqueidentifier  NOT NULL
);
GO

-- Creating table 'RequirementTicket'
CREATE TABLE [dbo].[RequirementTicket] (
    [RequirementTicket_Ticket_ID] uniqueidentifier  NOT NULL,
    [Children_ID] uniqueidentifier  NOT NULL
);
GO

-- Creating table 'PermissionSetPermission'
CREATE TABLE [dbo].[PermissionSetPermission] (
    [PermissionSetPermission_Permission_ID] uniqueidentifier  NOT NULL,
    [Children_ID] uniqueidentifier  NOT NULL
);
GO

-- Creating table 'AcePermission'
CREATE TABLE [dbo].[AcePermission] (
    [AcePermission_Permission_ID] uniqueidentifier  NOT NULL,
    [Permissions_ID] uniqueidentifier  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [ID] in table 'MilestoneSet'
ALTER TABLE [dbo].[MilestoneSet]
ADD CONSTRAINT [PK_MilestoneSet]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'CommentSet'
ALTER TABLE [dbo].[CommentSet]
ADD CONSTRAINT [PK_CommentSet]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'TicketSet'
ALTER TABLE [dbo].[TicketSet]
ADD CONSTRAINT [PK_TicketSet]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'PermissionSet'
ALTER TABLE [dbo].[PermissionSet]
ADD CONSTRAINT [PK_PermissionSet]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'AceSet'
ALTER TABLE [dbo].[AceSet]
ADD CONSTRAINT [PK_AceSet]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'EmployeeSet'
ALTER TABLE [dbo].[EmployeeSet]
ADD CONSTRAINT [PK_EmployeeSet]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'AssignmentSet'
ALTER TABLE [dbo].[AssignmentSet]
ADD CONSTRAINT [PK_AssignmentSet]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'ChangeSetSet'
ALTER TABLE [dbo].[ChangeSetSet]
ADD CONSTRAINT [PK_ChangeSetSet]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'TicketSet_Task'
ALTER TABLE [dbo].[TicketSet_Task]
ADD CONSTRAINT [PK_TicketSet_Task]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'TicketSet_Risk'
ALTER TABLE [dbo].[TicketSet_Risk]
ADD CONSTRAINT [PK_TicketSet_Risk]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'MilestoneSet_Project'
ALTER TABLE [dbo].[MilestoneSet_Project]
ADD CONSTRAINT [PK_MilestoneSet_Project]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'TicketSet_Requirement'
ALTER TABLE [dbo].[TicketSet_Requirement]
ADD CONSTRAINT [PK_TicketSet_Requirement]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'PermissionSet_PermissionSet'
ALTER TABLE [dbo].[PermissionSet_PermissionSet]
ADD CONSTRAINT [PK_PermissionSet_PermissionSet]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'TicketSet_Bug'
ALTER TABLE [dbo].[TicketSet_Bug]
ADD CONSTRAINT [PK_TicketSet_Bug]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [Comments_ID], [CommentComment_Comment_ID] in table 'CommentComment'
ALTER TABLE [dbo].[CommentComment]
ADD CONSTRAINT [PK_CommentComment]
    PRIMARY KEY NONCLUSTERED ([Comments_ID], [CommentComment_Comment_ID] ASC);
GO

-- Creating primary key on [MilestoneComment_Comments_ID], [Comments_ID] in table 'MilestoneComment'
ALTER TABLE [dbo].[MilestoneComment]
ADD CONSTRAINT [PK_MilestoneComment]
    PRIMARY KEY NONCLUSTERED ([MilestoneComment_Comments_ID], [Comments_ID] ASC);
GO

-- Creating primary key on [TicketComment_Comments_ID], [Comments_ID] in table 'TicketComment'
ALTER TABLE [dbo].[TicketComment]
ADD CONSTRAINT [PK_TicketComment]
    PRIMARY KEY NONCLUSTERED ([TicketComment_Comments_ID], [Comments_ID] ASC);
GO

-- Creating primary key on [RiskTicket_RelatedTickets_ID], [RelatedTickets_ID] in table 'RiskTicket'
ALTER TABLE [dbo].[RiskTicket]
ADD CONSTRAINT [PK_RiskTicket]
    PRIMARY KEY NONCLUSTERED ([RiskTicket_RelatedTickets_ID], [RelatedTickets_ID] ASC);
GO

-- Creating primary key on [AffectedProjects_ID], [Risks_ID] in table 'ProjectRisk'
ALTER TABLE [dbo].[ProjectRisk]
ADD CONSTRAINT [PK_ProjectRisk]
    PRIMARY KEY NONCLUSTERED ([AffectedProjects_ID], [Risks_ID] ASC);
GO

-- Creating primary key on [RiskMitigationPlans_MitigationPlan_ID], [MitigationPlans_ID] in table 'RiskMitigationPlans'
ALTER TABLE [dbo].[RiskMitigationPlans]
ADD CONSTRAINT [PK_RiskMitigationPlans]
    PRIMARY KEY NONCLUSTERED ([RiskMitigationPlans_MitigationPlan_ID], [MitigationPlans_ID] ASC);
GO

-- Creating primary key on [RiskContingencyPlan_ContingencyPlan_ID], [ContingencyPlans_ID] in table 'RiskContingencyPlan'
ALTER TABLE [dbo].[RiskContingencyPlan]
ADD CONSTRAINT [PK_RiskContingencyPlan]
    PRIMARY KEY NONCLUSTERED ([RiskContingencyPlan_ContingencyPlan_ID], [ContingencyPlans_ID] ASC);
GO

-- Creating primary key on [RequirementTicket_Ticket_ID], [Children_ID] in table 'RequirementTicket'
ALTER TABLE [dbo].[RequirementTicket]
ADD CONSTRAINT [PK_RequirementTicket]
    PRIMARY KEY NONCLUSTERED ([RequirementTicket_Ticket_ID], [Children_ID] ASC);
GO

-- Creating primary key on [PermissionSetPermission_Permission_ID], [Children_ID] in table 'PermissionSetPermission'
ALTER TABLE [dbo].[PermissionSetPermission]
ADD CONSTRAINT [PK_PermissionSetPermission]
    PRIMARY KEY NONCLUSTERED ([PermissionSetPermission_Permission_ID], [Children_ID] ASC);
GO

-- Creating primary key on [AcePermission_Permission_ID], [Permissions_ID] in table 'AcePermission'
ALTER TABLE [dbo].[AcePermission]
ADD CONSTRAINT [PK_AcePermission]
    PRIMARY KEY NONCLUSTERED ([AcePermission_Permission_ID], [Permissions_ID] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [Parent_ID] in table 'MilestoneSet'
ALTER TABLE [dbo].[MilestoneSet]
ADD CONSTRAINT [FK_MilestoneMilestone]
    FOREIGN KEY ([Parent_ID])
    REFERENCES [dbo].[MilestoneSet]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_MilestoneMilestone'
CREATE INDEX [IX_FK_MilestoneMilestone]
ON [dbo].[MilestoneSet]
    ([Parent_ID]);
GO

-- Creating foreign key on [Comments_ID] in table 'CommentComment'
ALTER TABLE [dbo].[CommentComment]
ADD CONSTRAINT [FK_CommentComment_Comment]
    FOREIGN KEY ([Comments_ID])
    REFERENCES [dbo].[CommentSet]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [CommentComment_Comment_ID] in table 'CommentComment'
ALTER TABLE [dbo].[CommentComment]
ADD CONSTRAINT [FK_CommentComment_Comment1]
    FOREIGN KEY ([CommentComment_Comment_ID])
    REFERENCES [dbo].[CommentSet]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CommentComment_Comment1'
CREATE INDEX [IX_FK_CommentComment_Comment1]
ON [dbo].[CommentComment]
    ([CommentComment_Comment_ID]);
GO

-- Creating foreign key on [MilestoneComment_Comments_ID] in table 'MilestoneComment'
ALTER TABLE [dbo].[MilestoneComment]
ADD CONSTRAINT [FK_MilestoneComment_Milestone]
    FOREIGN KEY ([MilestoneComment_Comments_ID])
    REFERENCES [dbo].[MilestoneSet]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Comments_ID] in table 'MilestoneComment'
ALTER TABLE [dbo].[MilestoneComment]
ADD CONSTRAINT [FK_MilestoneComment_Comments]
    FOREIGN KEY ([Comments_ID])
    REFERENCES [dbo].[CommentSet]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_MilestoneComment_Comments'
CREATE INDEX [IX_FK_MilestoneComment_Comments]
ON [dbo].[MilestoneComment]
    ([Comments_ID]);
GO

-- Creating foreign key on [TicketComment_Comments_ID] in table 'TicketComment'
ALTER TABLE [dbo].[TicketComment]
ADD CONSTRAINT [FK_TicketComment_Ticket]
    FOREIGN KEY ([TicketComment_Comments_ID])
    REFERENCES [dbo].[TicketSet]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Comments_ID] in table 'TicketComment'
ALTER TABLE [dbo].[TicketComment]
ADD CONSTRAINT [FK_TicketComment_Comments]
    FOREIGN KEY ([Comments_ID])
    REFERENCES [dbo].[CommentSet]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TicketComment_Comments'
CREATE INDEX [IX_FK_TicketComment_Comments]
ON [dbo].[TicketComment]
    ([Comments_ID]);
GO

-- Creating foreign key on [RiskTicket_RelatedTickets_ID] in table 'RiskTicket'
ALTER TABLE [dbo].[RiskTicket]
ADD CONSTRAINT [FK_RiskTicket_Risk]
    FOREIGN KEY ([RiskTicket_RelatedTickets_ID])
    REFERENCES [dbo].[TicketSet_Risk]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [RelatedTickets_ID] in table 'RiskTicket'
ALTER TABLE [dbo].[RiskTicket]
ADD CONSTRAINT [FK_RiskTicket_RelatedTickets]
    FOREIGN KEY ([RelatedTickets_ID])
    REFERENCES [dbo].[TicketSet]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_RiskTicket_RelatedTickets'
CREATE INDEX [IX_FK_RiskTicket_RelatedTickets]
ON [dbo].[RiskTicket]
    ([RelatedTickets_ID]);
GO

-- Creating foreign key on [AffectedProjects_ID] in table 'ProjectRisk'
ALTER TABLE [dbo].[ProjectRisk]
ADD CONSTRAINT [FK_ProjectRisk_Project]
    FOREIGN KEY ([AffectedProjects_ID])
    REFERENCES [dbo].[MilestoneSet_Project]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Risks_ID] in table 'ProjectRisk'
ALTER TABLE [dbo].[ProjectRisk]
ADD CONSTRAINT [FK_ProjectRisk_Risk]
    FOREIGN KEY ([Risks_ID])
    REFERENCES [dbo].[TicketSet_Risk]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ProjectRisk_Risk'
CREATE INDEX [IX_FK_ProjectRisk_Risk]
ON [dbo].[ProjectRisk]
    ([Risks_ID]);
GO

-- Creating foreign key on [RiskMitigationPlans_MitigationPlan_ID] in table 'RiskMitigationPlans'
ALTER TABLE [dbo].[RiskMitigationPlans]
ADD CONSTRAINT [FK_RiskMitigationPlans_Risk]
    FOREIGN KEY ([RiskMitigationPlans_MitigationPlan_ID])
    REFERENCES [dbo].[TicketSet_Risk]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [MitigationPlans_ID] in table 'RiskMitigationPlans'
ALTER TABLE [dbo].[RiskMitigationPlans]
ADD CONSTRAINT [FK_RiskMitigationPlans_MitigationPlan]
    FOREIGN KEY ([MitigationPlans_ID])
    REFERENCES [dbo].[TicketSet_Task]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_RiskMitigationPlans_MitigationPlan'
CREATE INDEX [IX_FK_RiskMitigationPlans_MitigationPlan]
ON [dbo].[RiskMitigationPlans]
    ([MitigationPlans_ID]);
GO

-- Creating foreign key on [RiskContingencyPlan_ContingencyPlan_ID] in table 'RiskContingencyPlan'
ALTER TABLE [dbo].[RiskContingencyPlan]
ADD CONSTRAINT [FK_RiskContingencyPlan_Risk]
    FOREIGN KEY ([RiskContingencyPlan_ContingencyPlan_ID])
    REFERENCES [dbo].[TicketSet_Risk]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [ContingencyPlans_ID] in table 'RiskContingencyPlan'
ALTER TABLE [dbo].[RiskContingencyPlan]
ADD CONSTRAINT [FK_RiskContingencyPlan_ContingencyPlan]
    FOREIGN KEY ([ContingencyPlans_ID])
    REFERENCES [dbo].[TicketSet_Task]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_RiskContingencyPlan_ContingencyPlan'
CREATE INDEX [IX_FK_RiskContingencyPlan_ContingencyPlan]
ON [dbo].[RiskContingencyPlan]
    ([ContingencyPlans_ID]);
GO

-- Creating foreign key on [RequirementTicket_Ticket_ID] in table 'RequirementTicket'
ALTER TABLE [dbo].[RequirementTicket]
ADD CONSTRAINT [FK_RequirementTicket_Requirement]
    FOREIGN KEY ([RequirementTicket_Ticket_ID])
    REFERENCES [dbo].[TicketSet_Requirement]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Children_ID] in table 'RequirementTicket'
ALTER TABLE [dbo].[RequirementTicket]
ADD CONSTRAINT [FK_RequirementTicket_Ticket]
    FOREIGN KEY ([Children_ID])
    REFERENCES [dbo].[TicketSet]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_RequirementTicket_Ticket'
CREATE INDEX [IX_FK_RequirementTicket_Ticket]
ON [dbo].[RequirementTicket]
    ([Children_ID]);
GO

-- Creating foreign key on [PermissionSetPermission_Permission_ID] in table 'PermissionSetPermission'
ALTER TABLE [dbo].[PermissionSetPermission]
ADD CONSTRAINT [FK_PermissionSetPermission_PermissionSet]
    FOREIGN KEY ([PermissionSetPermission_Permission_ID])
    REFERENCES [dbo].[PermissionSet_PermissionSet]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Children_ID] in table 'PermissionSetPermission'
ALTER TABLE [dbo].[PermissionSetPermission]
ADD CONSTRAINT [FK_PermissionSetPermission_Permission]
    FOREIGN KEY ([Children_ID])
    REFERENCES [dbo].[PermissionSet]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PermissionSetPermission_Permission'
CREATE INDEX [IX_FK_PermissionSetPermission_Permission]
ON [dbo].[PermissionSetPermission]
    ([Children_ID]);
GO

-- Creating foreign key on [AcePermission_Permission_ID] in table 'AcePermission'
ALTER TABLE [dbo].[AcePermission]
ADD CONSTRAINT [FK_AcePermission_Ace]
    FOREIGN KEY ([AcePermission_Permission_ID])
    REFERENCES [dbo].[AceSet]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Permissions_ID] in table 'AcePermission'
ALTER TABLE [dbo].[AcePermission]
ADD CONSTRAINT [FK_AcePermission_Permission]
    FOREIGN KEY ([Permissions_ID])
    REFERENCES [dbo].[PermissionSet]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AcePermission_Permission'
CREATE INDEX [IX_FK_AcePermission_Permission]
ON [dbo].[AcePermission]
    ([Permissions_ID]);
GO

-- Creating foreign key on [ReportTo_ID] in table 'EmployeeSet'
ALTER TABLE [dbo].[EmployeeSet]
ADD CONSTRAINT [FK_EmployeeEmployee]
    FOREIGN KEY ([ReportTo_ID])
    REFERENCES [dbo].[EmployeeSet]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_EmployeeEmployee'
CREATE INDEX [IX_FK_EmployeeEmployee]
ON [dbo].[EmployeeSet]
    ([ReportTo_ID]);
GO

-- Creating foreign key on [Replacement_ID] in table 'EmployeeSet'
ALTER TABLE [dbo].[EmployeeSet]
ADD CONSTRAINT [FK_EmployeeEmployee1]
    FOREIGN KEY ([Replacement_ID])
    REFERENCES [dbo].[EmployeeSet]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_EmployeeEmployee1'
CREATE INDEX [IX_FK_EmployeeEmployee1]
ON [dbo].[EmployeeSet]
    ([Replacement_ID]);
GO

-- Creating foreign key on [Project_ID] in table 'AssignmentSet'
ALTER TABLE [dbo].[AssignmentSet]
ADD CONSTRAINT [FK_AssignmentProject]
    FOREIGN KEY ([Project_ID])
    REFERENCES [dbo].[MilestoneSet_Project]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AssignmentProject'
CREATE INDEX [IX_FK_AssignmentProject]
ON [dbo].[AssignmentSet]
    ([Project_ID]);
GO

-- Creating foreign key on [User_ID] in table 'AssignmentSet'
ALTER TABLE [dbo].[AssignmentSet]
ADD CONSTRAINT [FK_EmployeeAssignment]
    FOREIGN KEY ([User_ID])
    REFERENCES [dbo].[EmployeeSet]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_EmployeeAssignment'
CREATE INDEX [IX_FK_EmployeeAssignment]
ON [dbo].[AssignmentSet]
    ([User_ID]);
GO

-- Creating foreign key on [Milestone_ID] in table 'TicketSet_Requirement'
ALTER TABLE [dbo].[TicketSet_Requirement]
ADD CONSTRAINT [FK_RequirementMilestone]
    FOREIGN KEY ([Milestone_ID])
    REFERENCES [dbo].[MilestoneSet]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_RequirementMilestone'
CREATE INDEX [IX_FK_RequirementMilestone]
ON [dbo].[TicketSet_Requirement]
    ([Milestone_ID]);
GO

-- Creating foreign key on [Project_ID] in table 'ChangeSetSet'
ALTER TABLE [dbo].[ChangeSetSet]
ADD CONSTRAINT [FK_ChangeSetProject]
    FOREIGN KEY ([Project_ID])
    REFERENCES [dbo].[MilestoneSet_Project]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ChangeSetProject'
CREATE INDEX [IX_FK_ChangeSetProject]
ON [dbo].[ChangeSetSet]
    ([Project_ID]);
GO

-- Creating foreign key on [ID] in table 'TicketSet_Task'
ALTER TABLE [dbo].[TicketSet_Task]
ADD CONSTRAINT [FK_Task_inherits_Ticket]
    FOREIGN KEY ([ID])
    REFERENCES [dbo].[TicketSet]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [ID] in table 'TicketSet_Risk'
ALTER TABLE [dbo].[TicketSet_Risk]
ADD CONSTRAINT [FK_Risk_inherits_Task]
    FOREIGN KEY ([ID])
    REFERENCES [dbo].[TicketSet_Task]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [ID] in table 'MilestoneSet_Project'
ALTER TABLE [dbo].[MilestoneSet_Project]
ADD CONSTRAINT [FK_Project_inherits_Milestone]
    FOREIGN KEY ([ID])
    REFERENCES [dbo].[MilestoneSet]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [ID] in table 'TicketSet_Requirement'
ALTER TABLE [dbo].[TicketSet_Requirement]
ADD CONSTRAINT [FK_Requirement_inherits_Ticket]
    FOREIGN KEY ([ID])
    REFERENCES [dbo].[TicketSet]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [ID] in table 'PermissionSet_PermissionSet'
ALTER TABLE [dbo].[PermissionSet_PermissionSet]
ADD CONSTRAINT [FK_PermissionSet_inherits_Permission]
    FOREIGN KEY ([ID])
    REFERENCES [dbo].[PermissionSet]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [ID] in table 'TicketSet_Bug'
ALTER TABLE [dbo].[TicketSet_Bug]
ADD CONSTRAINT [FK_Bug_inherits_Ticket]
    FOREIGN KEY ([ID])
    REFERENCES [dbo].[TicketSet]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------